#!/usr/bin/node

const log = console.log;
const koa = require('koa'),
      Router = require('koa-router'),
      bodyparser = require('koa-bodyparser'),
      tasks = require('../models/tasks.js');

let router = new Router();
router.prefix('/api/tasks');

router.get('/',async(ctx,next) => {
  let res = await tasks.getAllTasks(ctx.userId);
  ctx.body=res;
})

router.post('/',async (ctx,next)=>{
  let {task} = ctx.request.body;

  log(`得到待办事件列表,task=${task}`);
  ctx.body='添加成功'; 
})

router.put('/api/tasks/:id',async(ctx,next)=>{
  let {id} = ctx.params;
  let {task} = ctx.request.body;

  log(`修改待办事件列表 id=${id} task=${task}`);
  ctx.body='修改成功';
})

router.delete('/api/tasks/:id',async(ctx,next)=>{
  let {id} = ctx.params;
  log(`删除待办事件列表 id=${id}`);
  ctx.body='删除成功';
})

module.exports=router

log('hello world');

